package tests;

import database.*;
import org.junit.*;

public class TestQuestion {


	private BooleanQuestion q1;
	private SimpleQuestion q2;
	private NumericQuestion q3;
	private MultipleQuestion q4, q5, q6;
	
	@Before
	public void init() {
		
		String choices1[] = {"uno","dos","tres"};
		Integer ans1[] = {0, 1, 0};
        String choices2[] = {"choice1","choice2","choice3"};
        Integer ans2[] = {1, 1, 0};
        String choices3[] = {"choice1","choice3"};
        Integer ans3[] = {1, 1};
        
		q1 = new BooleanQuestion(true);
		
		q1.setQuestionText("prueba");
		q1.setLevel(0);
		q1.setScore(2);
		
		q2 = new SimpleQuestion("simple text");
		q2.setLevel(1);
		q2.setScore(3);

		q3 = new NumericQuestion(3.14151717d);
		q3.setQuestionText("cuanto vale pi?");
		q3.setLevel(2);
		q3.setScore(5);
		
        q4 = new MultipleQuestion(choices1, ans1);
        q4.setQuestionText("elija una opcion");
        q4.setLevel(0);
        q4.setScore(2);
        
        q5 = new MultipleQuestion(choices2, ans2);
        q5.setQuestionText("elija una opcion");
        q5.setLevel(0);
        q5.setScore(2);
        
        q6 = new MultipleQuestion(choices3, ans3);
        q6.setQuestionText("elija una opcion");
        q6.setLevel(0);
        q6.setScore(2);
	}
	
	@Test
	public void testEquals() {
		
		String choices1_copy[] = {"uno","dos","tres"};
		Integer ans1_copy[] = {0, 1, 0};
        String choices2_copy[] = {"choice1","choice2","choice3"};
        Integer ans2_copy[] = {1, 1, 0};
        String choices3_copy[] = {"choice1","choice3"};
        Integer ans3_copy[] = {1, 1};
		
		BooleanQuestion q1_copy = new BooleanQuestion(true);
		q1_copy.setQuestionText("prueba");
		q1_copy.setLevel(0);
		q1_copy.setScore(2);
		
		SimpleQuestion q2_copy = new SimpleQuestion("simple text");
		q2_copy.setLevel(1);
		q2_copy.setScore(3);
		
		NumericQuestion q3_copy = new NumericQuestion(3.141517178d);
		q3_copy.setQuestionText("cuanto vale pi?");
		q3_copy.setLevel(2);
		q3_copy.setScore(5);
		
		MultipleQuestion q4_copy = new MultipleQuestion(choices1_copy, ans1_copy);
		q4_copy.setQuestionText("elija una opcion");
        q4_copy.setLevel(0);
        q4_copy.setScore(2);
		
		MultipleQuestion q5_copy = new MultipleQuestion(choices2_copy, ans2_copy);
		q5_copy.setQuestionText("elija una opcion");
        q5_copy.setLevel(0);
        q5_copy.setScore(2);
        
        MultipleQuestion q6_copy = new MultipleQuestion(choices3_copy, ans3_copy);
        q6_copy.setQuestionText("elija una opcion");
        q6_copy.setLevel(0);
        q6_copy.setScore(2);
		
		Assert.assertTrue(this.q1.equals(q1_copy));
		Assert.assertTrue(this.q2.equals(q2_copy));
		Assert.assertTrue(this.q3.equals(q3_copy));
		Assert.assertTrue(this.q4.equals(q4_copy));
		Assert.assertTrue(this.q5.equals(q5_copy));
		Assert.assertTrue(this.q6.equals(q6_copy));
		
		Assert.assertFalse(this.q1.equals(q2_copy));
		Assert.assertFalse(this.q1.equals(q3_copy));
		Assert.assertFalse(this.q1.equals(q4_copy));
		Assert.assertFalse(this.q1.equals(q5_copy));
		
		Assert.assertFalse(this.q2.equals(q1_copy));
		Assert.assertFalse(this.q2.equals(q3_copy));
		Assert.assertFalse(this.q2.equals(q4_copy));
		Assert.assertFalse(this.q2.equals(q5_copy));
		
		Assert.assertFalse(this.q3.equals(q2_copy));
		Assert.assertFalse(this.q3.equals(q1_copy));
		Assert.assertFalse(this.q3.equals(q4_copy));
		Assert.assertFalse(this.q3.equals(q5_copy));
		
		Assert.assertFalse(this.q4.equals(q2_copy));
		Assert.assertFalse(this.q4.equals(q3_copy));
		Assert.assertFalse(this.q4.equals(q1_copy));
		Assert.assertFalse(this.q4.equals(q5_copy));
		
		Assert.assertFalse(this.q5.equals(q2_copy));
		Assert.assertFalse(this.q5.equals(q3_copy));
		Assert.assertFalse(this.q5.equals(q4_copy));
		Assert.assertFalse(this.q5.equals(q1_copy));		
	}
	
	@Test
	public void testValid() {
	
		this.q1.setUsrAns(q1.getAnswer());
		Assert.assertTrue(this.q1.validAnswer());
		
		this.q2.setUsrAns(q2.getAnswer());
		Assert.assertTrue(this.q2.validAnswer());
		
		this.q3.setUsrAns(q3.getAnswer());
		Assert.assertTrue(this.q3.validAnswer());
		
		this.q4.setUsrAns(q4.getCorrect());
		Assert.assertTrue(this.q4.validAnswer());
		
		this.q5.setUsrAns(q5.getCorrect());
		Assert.assertTrue(this.q5.validAnswer());
		
		this.q6.setUsrAns(q6.getCorrect());
		Assert.assertTrue(this.q6.validAnswer());
		
	}

}
